import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import an49 from '@mmstudio/an000049';
import { tbproject } from '../../../atoms/db';

const logger = anylogger('pages/api/project/edit.api');

export type Result = {
	ok: true;
} | {
	ok: false;
	message: string;
};

export type Message = ITbproject;

/**
 * 项目编辑
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { project_id, ...body } = req.body as Message;
		if (!body
			|| !project_id
		) {
			res.status(200).json({
				ok: false,
				message: '缺少必要的参数'
			}); return;
		}
		const r = await tbproject().first('*').where({


		}).andWhereNot({
			project_id
		});
		if (r) {
			res.status(200).json({
				ok: false,
				message: '内容已存在'
			}); return;
		}
		await tbproject().update(body).where({


			project_id




		});
		res.status(200).json({ ok: true });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
